package com.icw.resource.workflow.module.mgr;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.icw.decoupling.impl.module.RestfulMgrImpl;
import com.icw.resource.workflow.entity.WorkActivityInstance;
import com.icw.resource.workflow.entity.WorkActivityPropDefinition;
import com.icw.resource.workflow.entity.WorkActivityPropInstance;
import com.icw.resource.workflow.entity.WorkFlowInstance;
import com.icw.utility.PoEntityHelper;
import com.icw.utility.WorkFlowHelper;

public class WorkActivityPropInstanceRestfulMgr extends RestfulMgrImpl<WorkActivityPropInstance> {

	@Override
	public void post(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response, Map<String, Object> data) throws Exception {
		WorkActivityInstance activityInstance = srv().one(WorkActivityInstance.class, (String) PoEntityHelper.readValueByProperty(params, "activityInstance.id"));
		WorkActivityPropDefinition activityPropDefinition = srv().one(WorkActivityPropDefinition.class, (String) PoEntityHelper.readValueByProperty(params, "activityPropDefinition.id"));
		String defaultValueContent = (String) PoEntityHelper.readValueByProperty(activityPropDefinition, "defaultValue");
		if (defaultValueContent != null) {
			Map<String, Object> context = WorkFlowHelper.findRealVariableMap(// e
					WorkFlowHelper.findWorkVariableMap((WorkFlowInstance) PoEntityHelper.readValueByProperty(activityInstance, "stateInstance.flowInstance"))// e
			);
			PoEntityHelper.writeValueByProperty(params, "value", PoEntityHelper.parseJSEL(context, defaultValueContent));
		}
		super.post(params, request, response, data);
	}
}
